/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aal.bean;

import com.aal.entity.Category;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author quy
 */
@Stateless
public class CategoryFacade extends AbstractFacade<Category> implements CategoryFacadeLocal {

    @PersistenceContext(unitName = "AAL-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public CategoryFacade() {
        super(Category.class);
    }
    public Category findCategoryName(String categoryName){
        Query query = em.createNamedQuery("Category.findName").setParameter("categoryName", categoryName);
        return (Category) query.getSingleResult();
    }
    @Override
    public List<Category> searchCategory(String categoryName) {
        Query query = em.createNamedQuery("Category.findByCategoryName").setParameter("categoryName",'%'+categoryName+'%');
        return query.getResultList();
    }
}
